home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / Math / sin.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  778b  |  41 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "pml.h"
  4. #include "cordic.h"
  5.  
  6. static char     funcname[] = "sin";
  7.  
  8. extern CORDIC_Table CORDIC_Table0[1];
  9.  
  10. double
  11. sin(x)
  12.     double          x;
  13. {
  14.     double          x0, y0, z0;
  15.     double          D, t, temp;
  16.     int             Q;
  17.     struct exception xcpt;
  18.  
  19.     t = x / HALFPI;
  20.     D = modf(t, &temp);
  21.     Q = temp;
  22.  
  23.     if (Q < 0)
  24.         Q = -Q;
  25.  
  26.     x0 = ((Q & 2) ? -1.0 : 1.0);
  27.     y0 = 0.0;
  28.     z0 = D * HALFPI;
  29.  
  30.     if (Q & 1) {
  31.         CORDIC_rotate0(1, CORDIC_Table0, &x0, &y0, &z0);
  32.         xcpt.retval = x0 / CORDIC_Table0->kval;
  33.     }
  34.     else {
  35.         x0 = (Q & 2 ? -1.0 : 1.0);
  36.         CORDIC_rotate0(1, CORDIC_Table0, &x0, &y0, &z0);
  37.         xcpt.retval = y0 / CORDIC_Table0->kval;
  38.     }
  39.     return (xcpt.retval);
  40. }
  41.